package model;

import javax.servlet.http.HttpSession;

import entity.Admin;

public abstract class UserModel {
	
	private HttpSession session;
	public UserModel(HttpSession session) {
		this.session = session;
	}
	public boolean isAdmin() {
		Admin admin = (Admin)session.getAttribute("admin");
		if(admin!=null) {
			return true;
		}else {
			return false;
		}
	}
	
	public abstract String isNull();
	public abstract void add();
	public abstract void alter();
	public abstract void delete();
	public String doAdd() {
		if(!isAdmin()) {
			return "权限不够";
		}
		if(!isNull().equals("不为空")) {
			return isNull();
		}
		add();
		return "添加成功";
	}
	public String doAlter() {
		if(!isAdmin()) {
			return "权限不够";
		}
		if(!isNull().equals("不为空")) {
			return isNull();
		}
		alter();
		return "修改成功";
	}
	public String doDelete() {
		if(!isAdmin()) {
			return "权限不够";
		}
		delete();
		return "删除成功";
	}
	
}
